<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="tableData" size="small" style="width: 100%;">
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" class="demo-table-expand">
            <el-form-item label="请求路径">
              <span>{{ props.row.url }}</span>
            </el-form-item>
            <el-form-item label="请求方法">
              <span>{{ props.row.methodName }}</span>
            </el-form-item>
            <el-form-item label="请求参数">
              <!-- <span>{{ props.row.parameter }}</span> -->
              <pre style="display:flex;line-height: 18px;">{{ props.row.parameter }}</pre>
            </el-form-item>
            <el-form-item label="请求结果">
              <pre style="display:flex;line-height: 18px;">{{ props.row.result }}</pre>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column prop="username" label="用户名" />
      <el-table-column prop="nickName" label="昵称" />
      <el-table-column prop="ip" label="IP" />
      <!-- <el-table-column :show-overflow-tooltip="true" prop="address" label="IP来源" />
      <el-table-column prop="description" label="描述" />
      <el-table-column prop="browser" label="浏览器" /> -->
      <el-table-column prop="startTime" label="请求耗时" align="center">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.spendTime <= 300">{{ scope.row.spendTime }}ms</el-tag>
          <el-tag v-else-if="scope.row.spendTime <= 1000" type="warning">{{ scope.row.spendTime }}ms</el-tag>
          <el-tag v-else type="danger">{{ scope.row.spendTime }}ms</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="startTime" label="创建日期" width="180px" />
    </el-table>
    <!--分页组件-->
    <el-pagination
      style="margin-top: 10px"
      :total="pagination.total"
      :current-page="pagination.page"
      align="center"
      layout="total, prev, pager, next, sizes"
      @size-change="pagination.size"
      @current-change="pageChange"
    />
  </div>
</template>

<script>
import initData from '@/mixins/initData'
import { getLogs } from '@/api/monitor/log'
export default {
  name: 'Log',
  mixins: [initData],
  data() {
    return {
      tableData: [],
      initMethod: 'loadData',
      isAdd: false,
      delLoading: false
    }
  },
  created() {
    this.init()
  },
  methods: {
    loadData() {
      getLogs(this.queryParams).then(res => {
        const data = res.data

        this.dleChangePage(data.list.length === 0)
        this.pagination.total = data.total
        this.tableData = data.list
      }).finally(() => {
        this.loading = false
      })
    }
  }
}
</script>

<style>

</style>
